stage.set_axis(250)
pause_clicked = False
def hover():
x = stage.mouse_x()
y = stage.mouse_y()
if (x < -150 and x > -250) and (y < -200 and y > -250):
click_box.set_opacity(.7)
click_text.set_opacity(.7)
else:
click_box.set_opacity(1)
click_text.set_opacity(1)
def pause():
global pause_clicked
while not pause_clicked:
stage.wait(0.1)
pause_clicked = False
def pause_click(sprite):
global pause_clicked
pause_clicked = True
def hide_click():
click_box.hide()
click_text.hide()
def show_click():
click_box.show()
click_text.show()
def delete_click(sprite):
pass
def unpause():
pause_clicked = True
def pause_box():
global pause_clicked
show_click()
while not pause_clicked:
stage.wait(0.1)
pause_clicked = False
hide_click()
stage.set_background("silo")
code_back = codesters.Rectangle(0, 150, 450, 200, "black")
cow = codesters.Sprite("cow", -500, 0)
cow.hide()
pig = codesters.Sprite("pig", -500, 0)
pig.hide()
dog = codesters.Sprite('dog', -500, 0)
dog.hide()
cow.go_to(0,0)
pig.go_to(0,0)
dog.go_to(0,0)
num_y = 240
for counter in range(8):
num = codesters.Text(str(counter +1), -215, num_y, "gray")
num_y -= 25
line = codesters.Line(-194, 250, -194, 50, "gray")
list_name = codesters.Text("my_list = [ , , ]", -40, 215, "white")
list_values = codesters.Text('"cow" "pig" "dog"', 0, 215, "lightgreen")
y = 165
x = 0
spacing = 25
line1 = codesters.Text("for in :", x - 90, y, "white")
line1a = codesters.Text("value my_list", x - 81, y, "orange")
indent = 40
y-= spacing
line2 = codesters.Text("= codesters.Sprite( )", x-20 + indent, y, "white")
line2a = codesters.Text('sprite value', x-50+ indent, y, "orange")
spacer1 = codesters.Rectangle(-170, y, indent, spacing, "mediumpurple")
y-=spacing
line3 = codesters.Text('.go_to( , )', x- 53+ indent, y, "white")
line3a = codesters.Text('sprite', x - 160+ indent, y, "orange")
line3b = codesters.Text('-200 -180', x -28+ indent ,y, "dodgerblue")
spacer2 = codesters.Rectangle(-170, y, indent, spacing, "mediumpurple")
y-= spacing
line4 = codesters.Text('.glide_to( , )', x - 43+ indent, y, "white")
line4a = codesters.Text('sprite', x - 160+ indent, y, "orange")
line4b = codesters.Text('200 -180', x - 4+ indent, y, "dodgerblue")
spacer3 = codesters.Rectangle(-170, y, indent, spacing, "mediumpurple")
guide_rect = codesters.Rectangle(0, -50, 500, 60, "lightblue")
guide = codesters.Text("When you loop through a list, the loop runs as many times as there are values in the list.", 0, -50)
highlight = codesters.Rectangle(-60, 215, 45, 25, "yellow")
highlight.set_opacity(.5)
highlight.hide()
highlight2 = codesters.Rectangle(0, 140, 300, 25, None, "yellow")
highlight2.hide()
click_box = codesters.Rectangle(-200, -220, 125, 60, "green", "black")
click_text = codesters.Text("Continue", -200, -220, "white")
click_box.event_click(pause_click)
stage.event_mouse_move(hover)
pause_box()
def step_1(high_x, sprite):
highlight.set_x(high_x)
highlight.show()
highlight2.set_y(140)
highlight2.show()
guide.set_y(-120)
guide_rect.set_y(-120)
sprite.show()
def step_2(high_x, sprite):
highlight2.move_down(25)
guide.set_y(-50)
guide_rect.set_y(-50)
sprite.go_to(-200, -180)
def step_3(high_x, sprite):
highlight2.move_down(25)
sprite.glide_to(200, -180)
step_1(-60, cow)
guide.set_text('The first time the loop runs, it uses the image name "cow". The first line in the loop creates the sprite.')
pause_box()
step_2(-60, cow)
guide.set_text("The second command in the loop makes the sprite go to (-200, -180) on the stage.")
pause_box()
guide.set_text("The last command in the loop makes the sprite glide across the stage.")
step_3(-60, cow)
pause_box()
step_1(0, pig)
guide.set_text("When the loop repeats, it starts with the next value on the list. This command makes a pig sprite appear.")
pause_box()
guide.set_text("The second command in the loop makes the sprite go to (-200, -180) on the stage.")
step_2(0, pig)
pause_box()
guide.set_text("The last command in the loop makes the sprite glide across the stage.")
step_3(0, pig)
pause_box()
guide.set_text("When the loop repeats, it starts with the next value on the list.")
highlight.set_x(60)
highlight2.hide()
pause_box()
guide.set_text("Can you think of what will happen to the dog?")
list_name.hide()
list_values.hide()
highlight.hide()
tester = TestManager()
tester.display_success_message("Great job!")